' Dessert
' This program contains two logic errors.  Can you find them?
                                      
CLS
                                            ' print welcome message
PRINT "Welcome to the Dessert Program!"
PRINT                                  ' get user's name
INPUT "Please enter your name:  ", userName$
PRINT                                  ' get number of desserts
PRINT "How many desserts would you like to enter, "; userName$;
INPUT num%
PRINT

DIM desserts$(num%)           ' dimension string array
                                   
CALL GetData (desserts$(), num%, totalCalories%)  ' call subprogram
                                    
PRINT "The following is a list of "; userName$; "'s favorite desserts:"
PRINT

FOR i% = 1 TO num%
    PRINT "   "; desserts$(i%)       ' print array contents
NEXT i%

PRINT                                         ' print total number of calories
PRINT "The list contains a total of";
TEXTFACE 1
PRINT totalCalories%;
TEXTFACE 0
PRINT "calories!"

PRINT
INPUT "Press Return to continue", dummy$

END

SUB GetData (array$(), num%, totalCalories%) STATIC

' The GetData subprogram gets dessert information from the user.

FOR i% = 1 TO num%     ' loop num% times (passed from main program)
    INPUT "   Dessert name:  ", array$(num%)      ' get dessert name
    INPUT "   Calories in dessert:  ", calories%   ' get calories
    PRINT
    totalCalories% = calories%                            ' keep running total
NEXT i%

END SUB       ' return array$ and totalCalories% to main program